package com.study.web.controller.goal;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.study.common.core.controller.AppBaseController;
import com.study.common.core.domain.R;
import com.study.goal.domain.PlanExecutionLog;
import com.study.goal.service.IPlanExecutionLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * 计划执行日志
 * @author admin
 * @date 2023-04-17
 * @description
 */

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/planExecutionLog")
public class PlanExecutionLogController extends AppBaseController {

    private final IPlanExecutionLogService planExecutionLogService;

    /**
     * 开始计划第一次打卡
     *
     * @param studentId
     * @param planOccurrenceId
     * @param remark
     * @return
     */
    @SaCheckLogin
    @RequestMapping("/startCheckIn")
    public R<Void> startCheckIn(Long studentId, Long planOccurrenceId, String remark) {
        return toAjax(planExecutionLogService.startCheckIn(studentId, planOccurrenceId, remark));
    }

    /**
     * 完成计划打卡
     *
     * @param studentId
     * @param planOccurrenceId
     * @param remark
     * @param evidenceUrl
     * @return
     */
    @SaCheckLogin
    @RequestMapping("/completeCheckIn")
    public R<Void> completeCheckIn(Long studentId, Long planOccurrenceId, String remark, String evidenceUrl) {
        return toAjax(planExecutionLogService.completeCheckIn(studentId, planOccurrenceId, remark, evidenceUrl));
    }

    /**
     * 获取今日任务
     *
     * @param studentId
     * @param date
     * @return
     */
    @SaCheckLogin
    @RequestMapping("/getTodayTasks")
    public R<List<PlanExecutionLog>> getTodayTasks(Long studentId, LocalDate date) {
        return R.ok(planExecutionLogService.getTodayTasks(studentId, date));
    }

    /**
     * 获取执行统计
     *
     * @param goalAssignmentId
     * @param studentId
     * @return
     */
    @SaCheckLogin
    @RequestMapping("/getExecutionStats")
    public R<Object> getExecutionStats(Long goalAssignmentId, Long studentId) {
        return R.ok(planExecutionLogService.getExecutionStats(goalAssignmentId, studentId));
    }
}
